#include <glib.h>

static void _ptr_array_foreach_print_func(gpointer data, gpointer user_data)
{
    g_print("%s: %s(addr:%p) \n", (gchar *)user_data, (gchar *)data, data);
}

gint main(gint argc, gchar **argv)
{
    GPtrArray *parr = NULL;
    gint i = 0;
    gchar *str1 = "one";
    gchar *str2 = "two";
    gchar *str3 = "three";

    g_print("str1(addr:%p):%s \n", str1, str1);
    g_print("str2(addr:%p):%s \n", str2, str2);
    g_print("str3(addr:%p):%s \n", str3, str3);

    parr = g_ptr_array_sized_new(10);

    g_ptr_array_add(parr, (gpointer)str1);
    g_ptr_array_add(parr, (gpointer)str3);
    g_ptr_array_insert(parr, 1, (gpointer)str2);

    for(i=0; i<parr->len; i++) {
        g_print("parr[%d](addr:%p):%s(addr:%p) \n", 
            i, 
            &g_ptr_array_index(parr, i), 
            (gchar *)g_ptr_array_index(parr, i), 
            g_ptr_array_index(parr, i));
    }

    g_ptr_array_foreach(parr, _ptr_array_foreach_print_func, "foreach");

    g_ptr_array_free(parr, TRUE);

    return 0;
}